<?
if(isset($_POST['type'])){
    if($_POST['type']=="config"&&isset($_POST['host'])&&isset($_POST['user'])&&isset($_POST['pass'])&&isset($_POST['db'])){
        include('../libraries/data.lib.php');
        $host=data::word($_POST['host'], 'en', 0, ':');
        $user=data::word($_POST['user']);
        $pass=data::word($_POST['pass'], 'en', 0, '`~!@#$%^&*()-+={}[\]|;:<>,.?');
        $db=data::word($_POST['db']);
        
        ob_start();
        $connect=mysql_connect($host, $user, $pass)?'true':'false';
        $choose=mysql_selectdb($db)?'true':'false';
        ob_end_clean();
        
        if($connect=='true'&&$choose=='true'){
            $f=fopen('../../config.php', 'w');
            $s="<?\n\$host='".$host."';\n\$user='".$user."';\n\$pass='".$pass."';\n\$db='".$db."';\n?>";
            fwrite($f, $s);
            fclose($f);
        }
        print('{"connect":'.$connect.', "choose":'.$choose.'}');
    }
}
?>